﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
namespace Entity
{
    public class MONHOC
    {
        private String MAMH, TENMH;
        private float TCLT, TCTH;

        public String maMH
        {
            get { return MAMH; }
            set { MAMH = value; }
        }

        public String tenMH
        {
            get { return TENMH; }
            set { TENMH = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public float tclt
        {
            get { return TCLT; }
            set { TCLT = value; }
        }
        public float tcth
        {
            get { return TCTH; }
            set { TCTH = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public void hienthi_MonHoc(DataGridView dtgMonHoc)
        {
            try
            {
                DataTable datatable = new DataTable();
                datatable = dataBaseAccess.getDataTable("SELECT * FROM MONHOC");
                dtgMonHoc.DataSource = datatable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Hien Thi \n "+ ex.Message);
            }
        }

        public void them_MonHoc(MONHOC monhoc)
        {
            try
            {
                String excuteString = "INSERT INTO MONHOC VALUES('" + monhoc.maMH + "','"
                                                                    + monhoc.tenMH + "',"
                                                                    + monhoc.TCLT + ","
                                                                    + monhoc.TCTH + ")";
                dataBaseAccess.excuteNonQuery(excuteString);
            }
            catch (Exception ex)
            {
                MessageBox.Show(" Loi Them Mon Hoc \n" + ex.Message);
            }
        }

        public void sua_MonHoc(MONHOC monhoc)
        {
            try
            {
                String excuteString = "UPDATE MONHOC SET TENMH ='" + monhoc.tenMH +
                                                       "', TCLT =" + monhoc.TCLT +
                                                       ", TCTH =" + monhoc.TCTH +
                                                       "WHERE MAMH ='" + monhoc.maMH + "'";
                dataBaseAccess.excuteNonQuery(excuteString);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Sua Mon Hoc \n" + ex.Message);
            }
        }

        public void xoa_MonHoc(String mamonhoc)
        {
            try
            {
                String excuteString = "DELETE FROM MONHOC WHERE MAMH = '" + mamonhoc + "'";
                dataBaseAccess.excuteNonQuery(excuteString);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Xoa Mon Hoc \n" + ex.Message);
            }
        }

    }
}
